package com.diudiutechnology.www.yadiudiu.yadiudiu.house.MyActivity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter.BannersAdapter;
import com.diudiutechnology.www.yadiudiu.yadiudiu.house.MyAdapter.HousingDetailsAdapetr;
import com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter.TotalEvaluationAdapter;
import com.diudiutechnology.www.yadiudiu.util.utils.Sundry;
import com.diudiutechnology.www.yadiudiu.util.view.HorizontalListView;
import com.diudiutechnology.www.yadiudiu.util.view.ListViewForScrollView;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.BuyACarFragmentModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/1.
 * 买房详情
 */

public class HousingDetailsActivity extends Activity implements View.OnClickListener {
    @Bind(R.id.retur)
    LinearLayout retur;

    @Bind(R.id.more_see_layout)//查看更多
    LinearLayout more_see_layout;
    @Bind(R.id.more_see_text)//查看更 文字
    TextView more_see_text;
    @Bind(R.id.more_see_img)//查看更图片
            ImageView more_see_img;
    @Bind(R.id.more_layout)//查看更多 列表页
     LinearLayout more_layout;

    @Bind(R.id.release_listview)//评论
            ListViewForScrollView release_listview;
    List<BuyACarFragmentModel> buycarlist;
    TotalEvaluationAdapter adapter;

    @Bind(R.id.horizontalListView)//主力用户
            HorizontalListView horizontalListView;
    HousingDetailsAdapetr  housingDetailsAdapetr;

    @Bind(R.id.ad_pager)//轮播
            ViewPager adPager;
    @Bind(R.id.ad_layer)//圆圈
            LinearLayout adLayer;
    private final int HOME_AD_RESULT = 1;
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                // 广告
                case HOME_AD_RESULT:
                    adPager.setCurrentItem(adPager.getCurrentItem() + 1,
                            true);
                    break;
            }
        }

        ;
    };

    Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_housing_details);
        ButterKnife.bind(this);
        context=this;
        initView();
    }

    private void initView() {
        retur.setOnClickListener(this);
        more_see_layout.setOnClickListener(this);
        List<String> getinforresult = new ArrayList<>();
        getinforresult.add("1");
        getinforresult.add("1");
        getinforresult.add("1");
        getadvertising(getinforresult.size(), getinforresult);
        adapter=new TotalEvaluationAdapter(context);
        release_listview.setAdapter(adapter);

        housingDetailsAdapetr= new HousingDetailsAdapetr(context);
        horizontalListView.setAdapter(housingDetailsAdapetr);
        initData();
    }
    private void initData(){
//        buycarlist=new ArrayList<>();
//        for (int i=0;i<5;i++){
//            BuyACarFragmentModel model=new BuyACarFragmentModel();
//            model.setName("只是想改个名字");
//            model.setStar("2");
//            model.setDistance("");
//            model.setDate("老板服务态度挺好的，洗车也洗得很彻底，里外都收 拾得挺干净的");
//            model.setPraise("2017.05.31");
//            buycarlist.add(model);
//        }
//        adapter.addItem(buycarlist);

        List<BuyACarFragmentModel> buycar=new ArrayList<>();
        for (int i=0;i<5;i++){
            BuyACarFragmentModel model=new BuyACarFragmentModel();
            model.setName("只是想改个名字");
            buycar.add(model);
        }
        housingDetailsAdapetr.addItem(buycar);
    }
    //轮播广告
    public void getadvertising(final int size, final List<String> getinforresult) {
        adPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                Sundry.refreshPoint(adLayer, position % size, 0);
                if (mHandler.hasMessages(HOME_AD_RESULT)) {
                    mHandler.removeMessages(HOME_AD_RESULT);
                }
                mHandler.sendEmptyMessageDelayed(HOME_AD_RESULT, 3 * 1000);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                if (ViewPager.SCROLL_STATE_DRAGGING == arg0
                        && mHandler.hasMessages(HOME_AD_RESULT)) {
                    mHandler.removeMessages(HOME_AD_RESULT);
                }
            }
        });
        BannersAdapter adapter = new BannersAdapter(context, getinforresult, 0);
        adPager.setAdapter(adapter);
        Sundry.initPointsLayout(adLayer, context, size, 0);
        adPager.setCurrentItem(size * 1000, false);
        // 自动轮播线程
        mHandler.sendEmptyMessageDelayed(HOME_AD_RESULT, 3 * 1000);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.retur:
                finish();
                break;
            case R.id.more_see_layout:
                int visibility = more_layout.getVisibility();
                if (visibility!=0){
                    more_layout.setVisibility(View.VISIBLE);
                    more_see_text.setText("收起");
                    more_see_img.setVisibility(View.GONE);
                }else {
                    more_layout.setVisibility(View.GONE);
                    more_see_img.setVisibility(View.VISIBLE);
                    more_see_text.setText("查看更多");
                }
                break;

        }
    }
}

